home *** CD-ROM | disk | FTP | other *** search
- Path: en.com!usenet
- From: dpsm@en.com (Dale P. Smith)
- Newsgroups: comp.lang.c++
- Subject: Re: stl newbie help
- Date: Fri, 29 Mar 1996 17:14:49 GMT
- Organization: RheoActive
- Message-ID: <315c041b.118747@news.en.com>
- References: <315ae9a1.455438@news.en.com> <4jevo2$vae@nuacht.iol.ie>
- NNTP-Posting-Host: p8-ts4.en.net
- X-Newsreader: Forte Agent .99d/16.182
-
- David Byrden <Goyra@iol.ie> wrote:
- >dpsm@en.com (Dale P. Smith) wrote:
- >>What I want to understand how to do is declare a function class that
- >>can be used with something like for_each:
- >> for_each(Table.begin(), Table.end(), FunctionClassForEachThing);
- >>
- >>I know that I have to create a class that has operator() in it. What
- >>should this thing look like? I can't find (or can't see) any examples
- >>in the stl documentation.
- >>
- >
- >
- > Dale;
- >
- > The various algorithms require different functor signatures; void
- >return, bool return, value return, one parameter, 2 parameters etc. In
- >your example, this signature is required;
- >
- >
- > void Function( String& ) ;
- >
- >So, we could use an ordinary function, like the one above;
- >
- > void AppendAnE( String& ) ;
-
-
- Your example didn't work... but I just figured it out. The map
- container uses pairs. The signature I needed is:
-
- Function(pair<const key, data>&);
-
- This worked:
-
- void MyFunc(pair<const int, String>& x)
- {
- cout << x.first << ":" << x.second << "\n";
- }
-
- Thanks! All I needed was a little direction!
-
-
- Dale
-
-
- Dale P. Smith
- dpsm@en.com home
- dpsm@lubrizol.com work
-